home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / comps / gadgets / delphi10 / pcxbitmp / pcxbitmp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-18  |  2.3 KB  |  88 lines

  1. unit Pcxbitmp;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DelphPCX;
  8.  
  9. type
  10.   TPCXBitmap = class(TComponent)
  11.   private
  12.     { Private declarations }
  13.     FOnLoadPCX : TNotifyEvent;
  14.     FOnCreate  : TNotifyEvent;
  15.     FOnDestroy : TNotifyEvent;
  16.     ThePCXFO  : TPCXFileObject;
  17.   protected
  18.     { Protected declarations }
  19.   public
  20.     { Public declarations }
  21.     Width            : Longint;   { Holds the pixel width when done       }
  22.     Height           : Longint;   { Holds the pixel height when done      }
  23.     The_Name         : String;    { Holds the file name                   }
  24.     TheBMP           : TBitmap;
  25.     constructor Create( AOwner : TComponent ); override;
  26.     destructor Destroy; override;
  27.     procedure Load_PCX_File;
  28.   published
  29.     { Published declarations }
  30.     property FileName : String read The_Name write The_Name;
  31.     property OnCreate : TNotifyEvent read FOnCreate write FOnCreate;
  32.     property OnDestroy : TNotifyEvent read FOnDestroy write FOnDestroy;
  33.     property OnLoadPCXFile : TNotifyEvent read FOnLoadPCX write FOnLoadPCX;
  34.   end;
  35.  
  36. procedure Register;
  37.  
  38. implementation
  39.  
  40.  
  41. { This creates a file bitmap object }
  42. constructor TPCXBitmap.Create( AOwner : TComponent );
  43. begin
  44.   { call inherited FIRST! }
  45.   inherited Create( AOwner );
  46.   The_Name := '';
  47.   TheBMP := TBitmap.Create;
  48.   ThePCXFO := TPCXFileObject.Create;
  49.   if Assigned(FOnCreate) then OnCreate( Self );
  50. end;
  51.  
  52. { This is the destructor procedure }
  53. destructor TPCXBitmap.Destroy;
  54. begin
  55.   if Assigned(FOnDestroy) then OnDestroy(Self);
  56.   ThePCXFO.Free;
  57.   TheBMP.Free;
  58.   { call inherited last }
  59.   inherited destroy;
  60. end;
  61.  
  62. procedure TPCXBitmap.Load_PCX_File;
  63. var
  64.   Test_Win30_Bitmap : Longint;
  65.   Memory_DC         : HDC;
  66.   The_IO_Result     : Word;
  67.   ThePChar          : PChar;
  68.   Bitmap_Handle     : hBitmap;
  69.   Bitmap_Palette    : hPalette;
  70. begin
  71.   if Assigned(FOnLoadPCX) then OnLoadPCXFile( Self );
  72.   if The_Name = '' then exit;
  73.   GetMem( ThePChar , 256 );
  74.   StrPCopy( ThePChar , The_Name );
  75.   ThePCXFO.Init( ThePChar );
  76.   FreeMem( ThePChar , 256 );
  77.   ThePCXFO.LoadPCXBitmap( Bitmap_Handle , Bitmap_Palette );
  78.   TheBMP.Handle := Bitmap_Handle;
  79.   TheBMP.Palette := Bitmap_Palette;
  80. end;
  81.  
  82. procedure Register;
  83. begin
  84.   RegisterComponents('Gadgets', [TPCXBitmap]);
  85. end;
  86.  
  87. end.
  88.